<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="Webpixels">
    <title>购物车 - 西大网上书城</title>
    <!-- Preloader -->
    <!-- Favicon -->
    <link rel="icon" href="assets/img/brand/favicon.png" type="image/png">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="assets/libs/@fortawesome/fontawesome-free/css/all.min.css">
    <!-- Quick CSS -->
    <link rel="stylesheet" href="assets/css/quick-website.css" id="stylesheet">
    <link rel="stylesheet" href="./css/shopping.css">
</head>
<style>
    body {
        background-image: url('./images/background.jpg');
    }
</style>

<body>

<!-- Preloader -->
<div class="preloader">
    <div class="spinner-border text-primary" role="status">
        <span class="sr-only">Loading...</span>
    </div>
</div>

<!-- Navbar -->
<nav class="navbar navbar-expand-lg navbar-light bg-white">
    <div class="container">
        <a class="navbar-brand" href="index.html">西大网上书城</a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav ml-auto">
                <li class="nav-item active">
                    <a class="nav-link" href="index.html">首页</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="shopping.html">购物车</a>
                </li>
            </ul>
        </div>
    </div>
</nav>

<!-- Main content -->
<section class="slice py-7">
    <div class="container">
        <div class="row row-grid align-items-center">
            <div class="col-12 col-md-7 col-lg-6 order-md-1 pr-md-5">
                <h1 class="display-4 text-center text-md-left mb-3">
                    您的购物车
                </h1>
            </div>
        </div>
        <div class="row mt-5">
            <div class="col-12">
                <div class="table-responsive">
                    <table class="table table-striped table-hover">
                        <thead>
                        <tr>
                            <th scope="col">书名</th>
                            <th scope="col">作者</th>
                            <th scope="col">价格</th>
                            <th scope="col">发行日期</th>
                            <th scope="col">操作</th>
                        </tr>
                        </thead>
                        <tbody id="book-list">
                        <!-- 书籍列表将通过JavaScript动态插入 -->
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</section>

<!-- Footer -->
<footer class="position-relative" id="footer-main">
    <div class="footer pt-lg-7 footer-dark bg-dark">
        <div class="container pt-4">
            <div class="row">
                <div class="col-lg-4 mb-5 mb-lg-0">
                    <a href="index.html">
                        <img alt="Image placeholder" src="assets/img/brand/light.svg" id="footer-logo">
                    </a>
                    <p class="mt-4 text-sm opacity-8 pr-lg-4">西南大学，简称「西大」，位于重庆市北碚区缙云山山麓，是2005年7月经中国教育部批准，由原西南师范大学、原西南农业大学合并组建的教育部直属重点综合性大学 ，是中国首批雙一流高校，211工程建设学校，985优势学科创新平台项目建设大学，是国家布局在中西部的高水平综合型大学。</p>
                </div>
            </div>
        </div>
    </div>
</footer>

<!-- Core JS -->
<script src="assets/libs/jquery/dist/jquery.min.js"></script>
<script src="assets/libs/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="assets/libs/svg-injector/dist/svg-injector.min.js"></script>
<script src="assets/libs/feather-icons/dist/feather.min.js"></script>
<!-- Quick JS -->
<script src="assets/js/quick-website.js"></script>

<!-- Custom JS for shopping cart -->
<script>
    function fetchBooksFromCart() {
    // 假设服务器端有一个API端点返回购物车中的书籍信息
    $.ajax({
        url: '/api/cart/books', // 服务器端API
        type: 'GET',
        success: function(books) {
            const bookList = $('#book-list');
            bookList.empty(); // 清空现有列表

            books.forEach(book => {
                bookList.append(`
                    <tr>
                        <td>${book.name}</td>
                        <td>${book.author}</td>
                        <td>¥${book.price}</td>
                        <td>${book.publish}</td>
                        <td>
                            <button class="btn btn-danger btn-sm" onclick="removeFromCart(${book.id})">移除</button>
                        </td>
                    </tr>
                `);
            });
        },
        error: function(error) {
            console.error('Error fetching books from cart:', error);
        }
    });
}

    $(document).ready(function() {
        fetchBooksFromCart();
    });
</script>
</body>

</html>